@extends('admin.layouts.master')

@section('content')

<div class="row aw-list">
	<div class="col-md-12">
		<section class="row form-inline aw-list-head">
			<div class="col-sm-4">
				<div class="aw-head-add">
					<button class="btn btn-gules" v-on:click="List_Give_Layer()"><i class="icon-gift"></i> 赠送给用户</button>
				</div>
			</div>
		</section>
	</div>
	<div class="col-lg-12">
		<section class="panel aw-content">
			<header class="panel-heading">持券用户列表</header>
			<table class="table table-striped dataTable table-hover">
				<thead>
					<tr>
						<th>编号</th>
						<th>用户昵称</th>
						<th>手机号</th>
						<th>领取张数</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="(list, key) in lists" :data-key="key" :data-id="list.id">
						<td>@{{list.id}}</td>
						<td>@{{list.nickname}}</td>
						<td>@{{list.phone}}</td>
						<td>@{{list.number}}</td>
						<td>
							<button class="btn btn-gules btn-xs" v-on:click="List_Res(list.id,list.nickname)">
								<i class="icon-trash"></i> 收回
							</button>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="aw-text-center aw-list-null" v-if="lists.length==0">暂无数据</div>
			<vue-page :page_item="page_item" :page_this="page_this" :page_all="page_all" :Call_back="Call_back"></vue-page>
			<div class="col-md-12 aw-hide Js-layer-edit">
				<div class="aw-layer-edit-icon aw-layer-edit-station" style="width:340px;">
					<div class="col-md-12 aw-p0 form-group">
						<div class="aw-float-left aw-pr10" style="width:248px;">
							<input type="text" class="form-control" id="title" name="title" v-model="form.title" :value="form.title" placeholder="输入手机号或昵称" v-on:keyup.enter="Search_User()">
						</div>
						<a class="btn btn-green" v-on:click="Search_User()"><i class="icon-search"></i> 搜索</a>
					</div>
					<div class="Js-search-user-null" v-if="form.status==1">没有该用户,请检查手机号或昵称是否正确</div>
					<div class="Js-search-user" v-if="form.status==2">
						<div class="Js-search-user">是否向用户：@{{form.res_name}} 派发优惠券</div>
						<input type="text" class="form-control aw-mt30" id="number" name="number" v-model="form.number" :value="form.number" placeholder="输入要赠送的数量">
						<div class="col-md-12 aw-content-btn">
							<a class="btn btn-gules Js-layer-edit-btn" href="javascript:;" v-on:click="List_Give()">确定赠送</a>
							<a class="btn btn-gray Js-layer-colse" data-id="add" href="javascript:;">取消</a>
						</div>
					</div>
				</div>
			</div>
		</section>
	</div>
</div>

@section('pagejs')
@parent

<script type="text/javascript" src="/admin/js/vue-page.js"></script>
<script type="text/javascript" src="/admin/js/page.js"></script>
<script type="text/javascript">
var MJS_URLArry=URLArry;
MJS_URLArry.coupon_id=MJS_URLArry.id;
var AD_list={
	api:'/adminapi/coupon/user-coupon',
	form_data:MJS_URLArry,
	tips:false,
}
//默认数据
function VD_form(){
	return data={id:'',title:'',res_name:'',res_num:'',status:0,number:'',phone:'',coupon_id:MJS_URLArry.coupon_id}
}
var Ajax_Vue_Fun=function(vue_data){
	console.log('vue_data')
	console.log(vue_data)
	var Data_Vue=ajax_data_res(vue_data)
	Data_Vue.form={};//添加默认数据
	vm=new Vue({
		el:'#Vue-Body',
		data:Data_Vue,
		components:{
			'vue-page':Vpage
		},methods:{
			Call_back:function(page){
				Vm_Call_back_Page(page)
			},Search_User_Coupon_Text:function(id){
				if(!id){
					return '没有';
				}else{
					return '有 '+id+' 张';
				}
			},List_Give_Layer:function(id,key){
				console.warn('Vue-function:添加/编辑项目弹框事件 id='+id);
				$('.Js-search-user-null').fadeOut(0)
				Data_Vue.form=VD_form()
				layer_index_edit=layer.open({
					type:1,
					title:'派发优惠券',
					//closeBtn: 0, //不显示关闭按钮
					area: ['400px','280px'], //宽高
					content:$('.Js-layer-edit'),
				});
			},Search_User:function(){
				var AD_list_user={
					api:'/adminapi/user/user-list',
					form_data:this.form,
					tips:false,
				}
				getData(AD_list_user,function(vue_data_info){
					console.log('vue_data_info')
					console.log(vue_data_info)
					if(vue_data_info.count==0){
						vm.form.status=1;
					}else{
						vm.form.status=2;
						vm.form.res_name=vue_data_info.list[0].nickname;
						vm.form.res_num=vue_data_info.list[0].team_id;
						vm.form.id=vue_data_info.list[0].id;
						vm.form.phone=vue_data_info.list[0].phone;
					}
				})
			},List_Give:function(){
				var AD_push={
					api:'/adminapi/coupon/push',
					form_data:this.form,
					tips:'向 ['+this.form.res_name+'] 派发优惠券成功',
				}
				if(!this.form.number){
					msgTips(Placeholder_Text('#number'),2)
					$('#number').focus()
					return;
				}
				postData(AD_push,function(){
					Vm_Call_back_Page(vm.page_this)
					layer.close(layer_index_edit)
				})
			},List_Res:function(id,name){
				var tips='收回 [ '+name+' ] 的优惠券'
				var AD_del={
					api:'/adminapi/coupon/rec',
					form_data:{id:id,coupon_id:MJS_URLArry.coupon_id},
					tips:tips+'成功',
					msg:'是否'+tips+'？',
				}
				Vm_List_Status(AD_del)
			}
		}
	})
}
if(MJS_URLArry.id>0){
	getData(AD_list,Ajax_Vue_Fun)
}else{
	location.href='/admin/coupon/list?page_id=20';
}
</script>
@endsection

@endsection

